-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "bitmapfilter" #8786
Add "bitmapfilter" #8786
Conversation
Creating as a draft PR in part because if we go this direction I'll want to add more processing algorithms (sharpen, grayscale, sepia, edge detect for example). It also needs docstrings etc. I chose to make this separate from "bitmaptools" in case of source code growth, other name ideas are welcome. |
(there were no uses of port_realloc to fix)
bitmapfilter.morph is taken from openmv's imlib. It is substantially faster than blur/sharpen implemented in ulab, by up to 10x. It also avoids making many allocations.
I'll disable it on all boards where it doesn't fit when I next update the branch (approximately 18 boards) |
* weight can be any sequence (& test it) * improve error message * correct documentation of ``mask`` vs copypaste from openmv
This allows operations between channels in an image. It can be used for the following use cases: * Conversion to B&W or sepia * Adding color casts * Mixing or swapping arbitrary channels * Inverting or scaling arbitrary channels
we want it for memento, and maybe for qualia. we can add it elsewhere later if we want
These boards all previously had camera disabled too.
morph9 is a form of morph which performs 9 different convolutions, like a version of mix where each coefficient is a (2n+1)x(2n+1) matrix. Most use cases are covered by morph-then-mix, but some advanced operations may be more efficient to implement via morph9.
This reduces the time from about 133ms to about 122ms on my test image on the memento pycamera a similar change to morph did not produce a performance improvement, so I didn't include it.
.. and no specific use case for morph9 is known that can't be done with mix+morph. Saves ~1800 bytes on Memento
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall! Just a couple questions. No major concerns about the division between bindings and implementation.
Co-authored-by: Scott Shawcroft <scott@tannewt.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple more things. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple typos and one suggestion. Thanks!
//| mixed into the red output channel. The next 3 numbers are for | ||
//| green, and the final 3 are for blue. | ||
//| | ||
//| If ``weights`` `ChannelMixerOffset` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//| If ``weights`` `ChannelMixerOffset` | |
//| If ``weights`` is a `ChannelMixerOffset` |
//| object, then each channel is scaled and offset independently: | ||
//| The first two numbers are applied to the red channel: scale and | ||
//| offset. The second two number are applied to the green channel, | ||
//| and the last two numbers to the blue channel. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of explaining what number in each position does, it would be better to give examples when it is useful. The tuple has the individual number doc.
MP_DEFINE_CONST_FUN_OBJ_KW(bitmapfilter_mix_obj, 0, bitmapfilter_mix); | ||
|
||
//| def solarize(bitmap, threshold: float = 0.5, mask: displayio.Bitmap | None = None): | ||
//| """Creat a "solarization" effect on an image |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//| """Creat a "solarization" effect on an image | |
//| """Create a "solarization" effect on an image |
.. and update the test accordingly, fixing a bug discovered in the process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Well explained.
bitmapfilter.morph is taken from openmv's imlib.
It is substantially faster than blur/sharpen implemented in ulab, by up to 10x. It also avoids making many allocations.